# -*- encoding=utf-8 -*-

from froModuleDrivers.generalDeviceDriver import GeneralDeviceDriver
from froModuleDrivers.nioManager import NioManager
import time
from froModuleDrivers import LOGGER

# LOGGER.set_lvl("debug")

driver = GeneralDeviceDriver("192.168.50.110", 4001)
manager = NioManager(driver)
manager.run()

driver.showVersion()
driver.setWaitTime(0.5)
print(driver.getTemperatureHumidity())
print(driver.getTemperature())
print(driver.getHumidity())
print(driver.getLightIntensity())
print(driver.checkSmoke())
print(driver.getDistanceByUltrasound())
print(driver.getTriggerStatus())
print(driver.getTriggerStatus1())
print(driver.getTriggerStatus2())
print(driver.getColorDetectStatus())
print(driver.getColorDetectValueRGB())
print(driver.getColorDetectValueRGB565())
color_num = driver.getColorDetectColor()
if color_num != -1:
    print(driver.colorEncode[color_num])
else:
    print("检测失败")

# for i in range(100):  # 循环查询100次
#     speech_num = driver.recognizeSpeech(2)  # 查询缓存的语音识别结果,入参是语音识别节点的节点号
#     if -1 != speech_num:  # 判断是否检测到语音
#         print("识别到新的语句:", driver.voiceEncodeV3[speech_num]
#               )  # 打印新的语音识别结果，语音识别节点返回的编号与语句的对应关系在 voiceEncodeV2 字典中
#         # 可以在这里添加你的语音控制设备代码
#     time.sleep(0.5)  # 休眠0.5秒

print(driver.getColorDetectStatus())

driver.playSpeech(1,"今天星期四,明天星期五")
driver.setPulseOutput(5,20000000,1000000)
print(driver.getPulseOutput(5))
driver.setServoAngle(5,90)
print(driver.getServoAngle(5))
driver.setOutput5V(12,1)
print(driver.getOutput5V(12))
driver.setOutput5V(12,1)
print(driver.getOutput5V(12))
driver.setMotor5V(13,1,80)
print(driver.getMotor5V(13))
driver.setMotorClockwiseTime(13, 50, 500)
driver.setMotorCounterclockwiseTime(14, 50, 1.8)
time.sleep(2.5)
driver.setMotorClockwiseTime(14, 50, 2.5)
print(driver.getMotor5VAllStatus(13))
print(driver.getMotor5VAllStatus(14))
driver.setMotorCounterclockwiseTime(13, 50, 5)
driver.setMotorCounterclockwiseTime(14, 50, 5)
print(driver.getMotor5VAllStatus(13))
time.sleep(3)
print(driver.getMotor5VAllStatus(13))
time.sleep(3)
print(driver.getMotor5VAllStatus(13))
driver.setLanternMode(6,5,20)
time.sleep(1)
print(driver.getLanternStatus(6))
driver.setLanternMode(6,2,20)
time.sleep(1)
driver.setLanternSpecialMode(6)
time.sleep(1)
driver.setLanternByEachLedColor(6,6,[0,0,0,0,0,0])
time.sleep(1)
color=[0x07E0,0x001F,0xF800,0x07E0,0x001F,0xF800]
driver.setLanternByEachLedColor()
time.sleep(1)
driver.setLanternByEachLedColor(6,6,color)
time.sleep(1)
driver.setLanternByLedColor(6,6,0xF808)
time.sleep(1)
driver.setLanternMode(6,0,20)
time.sleep(1)
manager.shutdownGracefully()  # 等待指令执行完毕后系统退出
